package com.cskaoyan.controller;

import com.cskaoyan.bean.CskaoyanmallAd;
import com.cskaoyan.bean.CskaoyanmallTopic;
import com.cskaoyan.bean.bo.ExtensionTopicCreatBo;
import com.cskaoyan.bean.bo.ExtensionUpdateTopicBo;
import com.cskaoyan.bean.vo.BaseRespVo;
import com.cskaoyan.bean.vo.TopicVo;
import com.cskaoyan.service.ExtensionTopicService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * 推广管理
 * 话题管理(专题管理)
 * by 桂圆
 */
@RestController
public class ExtensionTopicController {
    @Autowired
    ExtensionTopicService extensionTopicService;

    // GET /admin/topic/list?title=%E5%A5%BD&
    // subtitle=%E4%BB%BD

    /**
     * 查询话题+显示话题首页
     *
     * @return
     */
    @RequiresPermissions("admin:topic:list")
    @GetMapping("admin/topic/list")
    public BaseRespVo getTopic(Integer page, Integer limit, String sort, String order, String title, String subtitle) {

        TopicVo topicVo = extensionTopicService.vagueQueryTopic(page, limit, sort, order, title, subtitle);

        return BaseRespVo.success(topicVo);
    }

    /**
     * 话题删除--逻辑删除
     */
//    POST /admin/topic/delete HTTP/1.1
    @RequiresPermissions("admin:topic:delete")
    @PostMapping("admin/topic/delete")
    public BaseRespVo delTopic(@RequestBody CskaoyanmallTopic topicBo) {

        Integer effectRows = extensionTopicService.deleteTopic(topicBo);

        if (effectRows != 1) {
            // TODO:
        }

        return BaseRespVo.success();
    }

//    POST /admin/topic/create HTTP/1.1

    /**
     * 添加专题(创建专题)
     */
    @RequiresPermissions("admin:topic:create")
    @PostMapping("admin/topic/create")
    public BaseRespVo creatTopic(@RequestBody ExtensionTopicCreatBo topicBo) {
//      TODO: 将list转为数组类型的字符串
        CskaoyanmallTopic topicVo = extensionTopicService.creatTopic(topicBo);

        return BaseRespVo.success(topicVo);
    }


    //    POST /admin/topic/update HTTP/1.1
    @RequiresPermissions("admin:topic:update")
    @PostMapping("admin/topic/update")
    public BaseRespVo updateTopic(@RequestBody ExtensionUpdateTopicBo topicBo) {

        CskaoyanmallTopic topicVo = extensionTopicService.updateTopic(topicBo);

        return BaseRespVo.success(topicVo);
    }
}
